"""
请求参数模型
"""
from typing import List, Any, Optional

from pydantic import BaseModel, Field, EmailStr, AnyUrl

from .model import UserBase, RoleOut


class Token(BaseModel):
    access_token: str = Field(..., description='Token值')
    token_type: str = Field(..., description='Token类型')


class Login(BaseModel):
    username: str = Field(..., description='用戶名', max_length=16)
    password: str = Field(..., description='密碼', max_length=32)


class RoleStatus(BaseModel):
    id: int
    status: bool


class PermIds(BaseModel):
    permission: List[int]


class ChangePassword(BaseModel):
    passwordOld: str = Field(..., description='用戶名', max_length=16, min_length=6)
    passwordNew: str = Field(..., description='用戶名', max_length=16, min_length=6)
    confirmPassword: str = Field(..., description='用戶名', max_length=16, min_length=6)


# 创建账号需要验证的条件
class UserRegister(UserBase):
    confirm: str = Field(..., description='确认密码')

    class Config:
        """
        schema_extra中设置参数的例子，在API文档中可以看到
        """
        schema_extra = {
            'example': {
                'username': 'guest',
                'nickname': '访客',
                'email': 'guest@example.com',
                'mobile': '10086',
                'password': '123456',
                'confirm': '123456',
                'avatar': 'https://img2.woyaogexing.com/2021/05/03/dfcfaaffa8ed4e1a819eba8c10b856d4!400x400.jpeg'
            }
        }


class UserCreate(UserBase):
    password: Optional[str]
    email: str
    role_id: str
    dept_id: int


class UserOut(UserBase):
    id: int
    role: RoleOut
    role_id: str
    dept_id: int
    created_at: Any


class UserAccountInfo(BaseModel):
    email: EmailStr
    nickname: str = Field(default=None, max_length=64)
    realName: str = Field(default=None, max_length=64)
    remark: str = Field(default=None, max_length=256)
    mobile: str = Field(default=None, max_length=64)
    address: str = Field(default=None, max_length=64)


class UserExist(BaseModel):
    username: str = Field(..., max_length=32, description='用户名')
